﻿<%@ Page Language="C#" MasterPageFile="~/Master/Default.Master" AutoEventWireup="true" CodeBehind="addScribe.aspx.cs" Inherits="PointTracker.addScribe" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderHead" runat="server">
    <script language="javascript" type="text/javascript">
        // Verifies that all the necessary fields for adding a professor are filled in        
        function VerifyFields() {
            var errors = false;
            var list = "";

            document.getElementById("Errors").setAttribute("class", "error");
            list += "<ul>";

            if (document.getElementById("<%= TextBoxFname.ClientID %>").value == "") {
                list += "<li>The first name field cannot be empty</li>";
                errors = true;
            }
            if (document.getElementById("<%= TextBoxLname.ClientID %>").value == "") {
                list += "<li>The last name field cannot be empty</li>";
                errors = true;
            }
            if (document.getElementById("<%= TextBoxEmail.ClientID %>").value == "") {
                list += "<li>The e-mail field cannot be empty</li>";
                errors = true;
            }
            if (document.getElementById("<%= TextBoxPassword.ClientID %>").value == "") {
                list += "<li>The password field cannot be empty</li>";
                errors = true;
            }

            if (document.getElementById("<%= TextBoxEmail.ClientID %>").value != "" && !echeck(document.getElementById("<%= TextBoxEmail.ClientID %>").value)) {
                list += "<li>The e-mail provided is invalid</li>";
                errors = true;
            }

            document.getElementById("Errors").innerHTML = list;

            if (errors) {
                document.getElementById("<%= TextBoxPassword.ClientID %>").value = "";
            }

            document.getElementById("Errors").innerHTML += "</ul>";
            return !errors;
        }

        function echeck(str) {
            var at = "@"
            var dot = "."
            var lat = str.indexOf(at)
            var lstr = str.length
            var ldot = str.indexOf(dot)
            if (str.indexOf(at) == -1) {
                return false
            }

            if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
                return false
            }

            if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
                return false
            }

            if (str.indexOf(at, (lat + 1)) != -1) {
                return false
            }

            if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
                return false
            }

            if (str.indexOf(dot, (lat + 2)) == -1) {
                return false
            }
            if (str.indexOf(" ") != -1) {
                return false
            }

            return true
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderBody" runat="server">
    <fieldset>
    <legend>Add a Scribe</legend>
    <div id="Errors"></div>
    <dl id="addRemoveForm">
        <dt><label>First Name:</label></dt>
        <dd><asp:TextBox ID="TextBoxFname" runat="server"></asp:TextBox></dd>
        <dt><label>Last Name:</label></dt>
        <dd><asp:TextBox ID="TextBoxLname" runat="server"></asp:TextBox></dd>
        <dt><label>E-mail:</label></dt>
        <dd><asp:TextBox ID="TextBoxEmail" runat="server"></asp:TextBox></dd>
        <dt><label>Password:</label></dt>
        <dd><asp:TextBox ID="TextBoxPassword" TextMode="Password" runat="server"></asp:TextBox></dd>
        <%--<dt><label>Verify Passowrd:</label></dt>
        <dd><asp:TextBox ID="TextBoxVpassword" TextMode="Password" runat="server"></asp:TextBox></dd>--%>
    </dl>
    
    <asp:Button ID="ButtonAddScribe" OnClick="AddScribe" OnClientClick="return VerifyFields();" runat="server" Text="Add Scribe"/>
    </fieldset>
</asp:Content>